import { deleteLibrarySize, getLibrarySize, librarySizeList } from "@/api/service/library/size";

import { resetForm, sizeForm, sizeShowForm } from "./form";
import { sizeKeys, sizeQuery, sizeTable } from "./table";

export const sizeList = async () => {
  sizeTable.value.loading = true;
  const data = await librarySizeList(sizeQuery.value);
  sizeTable.value.data = data.rows;
  sizeQuery.value.total = data.total;
  sizeTable.value.loading = false;
};

export const sizeEdit = async (id?: string) => {
  const targetId = id || sizeKeys.value[0];
  const data = await getLibrarySize(targetId);
  sizeForm.value = data.data;
  sizeShowForm.value = true;
};

export const sizeCreate = async () => {
  resetForm();
  sizeShowForm.value = true;
};

export const sizeDelete = async (id?: string) => {
  if (!id) return;
  const targetId = [id];
  await deleteLibrarySize(targetId);
  await sizeList();
  sizeKeys.value = [];
};
